<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>十进制转16进制</title>
</head>
<body>
<script type="application/javascript">
  function getNumStr (num) {
    let res = num
    switch (num) {
      case 10:
        res = 'A'
        break
      case 11:
        res = 'B'
        break
      case 12:
        res = 'C'
        break
      case 13:
        res = 'D'
        break
      case 14:
        res = 'E'
        break
      case 15:
        res = 'F'
        break
    }
    return res
  }
  function Num10To16 (num, res) {
    let code = Math.floor(num / 16)
    let wei = num % 16
    res = getNumStr(wei) + res
    if (code < 16) {
      if (code === 0) return res
      return code + res
    }
    else return Num10To16(code, res)
  }
  console.log(Num10To16(11316, ''))
</script>
</body>
</html>
